<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加合同</title>
    <link rel="stylesheet" type="text/css" href="../../static/leftCommon.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/common.css"/>
    <link rel="stylesheet" type="text/css" href="../static/css/project.css"/>
</head>
<body>
    <div class="rightBox">
        <div class="documentName" style="margin-bottom: 50px;">新 增 物 资 合 同 审 核</div>
        <!-- 流程图 -->
        <div class="searchconstract">
        
        </div>
        <div class="fillFor">
            <p class="fillto">填写说明</p>
            <ul class="explain">
                <li style="height: 20px;width: 920px"><span class="close pointer" style="float:right;color:red;">收起</span></li>
                <li>1、带*输入框需必填。</li>
                <li>2、上传询比价附件需注意：询价函、报价单、报价汇总、三重一大会议纪要、会议签到表、影像资料、合同文本。</li>
                <li>3、上传竞争性谈判、邀请招标、公开招标附件需注意：评标报告、中标单位报价单、三重一大会议纪要，会议签到表、影像资料、合同文本。</li>
                <li>4、上传文件时，若多文件需要同时上传，请<span style="color: red;">打包文件后上传</span>。</li>
            </ul>
        </div>
        <!-- 申请表 -->
        <div class="condetailList" style="margin-top:50px;margin-left: 10%;">
            <p class="conList">物 资 合 同 审 核 流 程 表</p>
            <!-- 里面具体的表格 -->
            <table border="0" class="conList" cellpadding="1" cellspacing="0">
                <tr id="rowHeight">
                    <td class="interval">项目工程名称</td>
                    <td colspan="3">
                        <input type="text" id="projectName" class="sameInput" readonly="readonly" style="outline:none;">
                    </td>
                    <td class="interval"><span style="color:red;">*</span>合同编号</td>
                    <td colspan="3"><input type="text" id="contractNo" class="sameInput contitle"  class=""/></td>
                </tr>
                <tr id="rowHeight">
                    <td class="interval"><span style="color:red;">*</span>是否采用公司格式合同</td>
                    <td colspan="7" style="text-align:left;" id="radios"> 
                        <label for="sc" class="lt"><input type="radio" name="dan" id="sc" value="true" class="lt" style="margin-top: 13px;margin-right:5px;" checked>是</label>
                        <label for="lt" class="lt"><input type="radio" name="dan" id="lt" value="false" class="lt" style="margin-top: 13px;margin-right:5px;">否</label>
                    </td>
                </tr>
                <tr id="rowHeight">
                    <td class="interval">供应商名称</td>
                    <td colspan="3">
                        <input type="text" id="name" class="sameInput" surId="">
                    </td>
                    <td class="interval">供货材料品种</td>
                    <td colspan="3" id="classify" style="text-indent: 20px;">
                        <!-- <input type="text"> -->
                    </td>
                </tr>
                <!-- 弹窗 -->
                <!-- <div class="openWin none">
                    <ul class="firNav">
                        <li class="comSelf pointer" id="comSelf">本项目部供应商</li>
                        <li class="comAll pointer" id="comAll">全公司供应商</li>
                    </ul>
                    <div class="secNav">
                        <p class="self none"></p>
                        <p class="all none"></p>
                    </div>
                    <button type="button" id="btnS" style="position: absolute;right: 10px;bottom: 10px;">确认</button>
                </div> -->
                <tr id="rowHeight">
                    <td class="interval"><span style="color:red;" class="">*</span>运距（km）</td>
                    <td colspan="3"><input type="text" id="loadDistance" class="sameInput loadTitle" /></td>
                    <td class="interval" class=""><span style="color:red;">*</span>单价</td>
                    <td colspan="3"><input type="text" id="price" class="sameInput priceTitle listToDetail" autocomplete="off"/></td>
                <tr id="rowHeight">
                    <td rowspan="2" class="interval">供方资信状态</td>
                    <td class="interval">营业执照注册号</td>
                    <td class="interval">营业执照有效期</td>
                    <td class="interval">营业执照注册资金</td>
                    <td class="interval">生产许可证号</td>
                    <td class="interval">生产许可证有效期</td>
                    <td class="interval">资信等级</td>
                    <td class="interval">诚信状况</td>
                </tr>
                <tr id="rowHeight">
                    <td><input type="text" id="businessLicense"  class="sameInput"/></td>
                    <td><input type="text" id="businessExpireDate" class="sameInput"/></td>
                    <td><input type="text" id="businessRegisterMoney" class="sameInput"/></td>
                    <td><input type="text" class="sameInput" id="productLicence"/></td>
                    <td><input type="text" class="sameInput" id="productExpireDate"/></td>
                    <td><input type="text" class="sameInput" id="creditLevel"/></td>
                    <td><input type="text" class="sameInput hontitle" id="honestLevel"/></td>
                </tr>
                <tr id="rowHeight">
                    <td class="interval"><span style="color:red;">*</span>招标方式</td>
                    <td colspan="6" >
                        <div id="bidtd" style="width:100%;height:40px;" class="bidChoose">
                            <label for="bid1" style="float:left;margin-left:20px;"><input type="radio" value="1" name="bid" id="bid1" class="lt" style="margin-top: 13px;margin-right:5px;" checked>询比价</label>
                            <label for="bid2" style="float:left;margin-left:20px;"><input type="radio" value="2" name="bid" id="bid2" class="lt" style="margin-top: 13px;margin-right:5px;">竞争性谈判</label>
                            <label for="bid3" style="float:left;margin-left:20px;"><input type="radio" value="3" name="bid" id="bid3" class="lt" style="margin-top: 13px;margin-right:5px;">邀请招标</label>
                            <label for="bid4" style="float:left;margin-left:20px;"><input type="radio" value="4" name="bid" id="bid4" class="lt" style="margin-top: 13px;margin-right:5px;">公开招标</label>
                        </div>
                    </td>
                    <td style="position: relative;">
                        <button type="button" class="upandshow uploadfile listToDetail" ><span style="color:red;">*</span>上传文件</button>
                        <input type="file" name="" id="upload" style="display:none;">
                        <input type="text" id="bidfile" disabled="disabled" style="width: 94px;position: absolute;top: 12px;left:70px;border:none;outline: none;background: none;">
                    </td>
                </tr>
                <tr style="height:120px;" class="none">
                    <td class="interval">项目物资部审核意见</td>
                    <td colspan="7" style="height:120px;">
                        <textarea id="materialsComment" class="" style="width: 100%;height:100%;float: left; border: none; resize: none;"/></textarea>
                    </td>
                </tr>
                <tr style="height:120px;" class="none">
                    <td class="interval">项目计划部审核意见</td>
                    <td colspan="7" style="height:120px;">
                        <textarea id="planComment" class="" style="width: 100%;height:100%;float: left; border: none; resize: none;"/></textarea>
                    </td>
                </tr>
                <tr style="height:120px;" class="none">
                    <td class="interval">项目财务部审核意见</td>
                    <td colspan="7" style="height:120px;">
                        <textarea id="planComment" class="" style="width: 100%;height:100%;float: left; border: none; resize: none;"/></textarea>
                    </td>
                </tr>
                <tr style="height:120px;" class="none">
                    <td class="interval">项目书记审核意见</td>
                    <td colspan="7" style="height:120px;">
                        <textarea id="secretaryComment" class="" style="width: 100%;height:100%;float: left; border: none; resize: none;"/></textarea>
                    </td>
                </tr>
                <tr style="height:120px;" class="none">
                    <td class="interval">项目经理审核意见</td>
                    <td colspan="7" style="height:120px;">
                        <textarea  id="manageComment" class="" style="width: 100%;height:100%;float: left; border: none; resize: none;"/></textarea>
                    </td>
                </tr>
            </table>
            <!-- 点击单价弹出表格 -->
            <div class="shade none"></div>
            <div class="pricetableList none">
                <table id="pricelist" cellspacing="0" cellpadding="0">
                    <thead>
                        <tr>
                            <th>名称</th>
                            <th>型号</th>
                            <th>单价</th>
                            <th>运费</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr onclick="">
                            <td><input type="text" class="sameInput name"></td>
                            <td><input type="text" class="sameInput model"></td>
                            <td><input type="text" class="sameInput price"></td>
                            <td><input type="text" class="sameInput freight"></td>
                            <td style="text-align: center;"><button type="button" class="add upandshow">添加</button><button type="button" class="over upandshow none">删除</button></td>                        
                        </tr>   
                    </tbody>
                </table>
                <div class="explan">
                    <p>总说明：</p>
                    <textarea name="" id="remark" cols="30" rows="10" style="width: 100%;height:80px;resize: none;"></textarea>
                </div>
                <button type="button" class="btnBlue" id="sure">确定</button>
                <button type="button" class="btnBlue" id="no">取消</button>
            </div>
            <p style="text-align:center;margin:20px 0;">
                <button type="button" id="submit" class="btnBlue">提 交</button>
            </p>
        </div>
    </div>
</body>
</html>
<script src="../../static/js/jquery-1.8.3.js"></script>
<script src="../../static/dx.js"></script>
<script src="../../static/laydate/laydate.js"></script>
<script src="../static/js/progress.js"></script>
<script src="../static/js/tip.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    var surveyId = DX.getParam('surveyId');
    randerContract(surveyId);
    
    
    // 填写说明收起
    $('.close').toggle(
        function(){
            $(this).parent().siblings().slideUp(200);
            $(this).html('查看更多');
        },
        function(){
            $(this).parent().siblings().slideDown(200);
            $(this).html('收起');
        }
    )

    // 上传
    $('.uploadfile').click(function(){
        $('#upload').click();
    })
    $('#upload').change(function(){
        $('#bidfile').val($(this).val());
        DX.uplaodFile({
            'id':'upload',
            'url':'/materials/file/upload',
            'change':$(this)[0],
            'callBack':function(res){
                console.log(res)
                $('.uploadfile').attr('oid',res.data);
            }
        })
    })  
})

function randerContract(surveyId){

    DX.ajax_method({
        'type':'GET',
        'url':'/materials/supply/supplierSurvey/findById',
        'param':{id:surveyId},
        'callBack':function(res){
            // console.log(res.data)
            doRander(res.data);
        }
    })
}


//资信等级
var creditLevelMap = {1:'1A',2:'2A',3:'3A','':''}
function doRander(data){
    console.log(data)
    for(var j in data){
        if(!data[j] && data[j] != 0){
            data[j] = '';
        }
    }
    // 流程
    $('.searchconstract').progress({
        active:0,
        data: [{
                title: '提交资料',
                date: getDate()
            },
            {
                title: '项目物资部审核',
                date: ''
            },
            {
                title: '项目计划部审核',
                date: ''
            },
            {
                title: '项目财务部审核',
                date: ''
            },
            {
                title: '项目书记审核',
                date: ''
            },
            {
                title: '项目经理审核',
                date: ''
            },
            {
                title: '公司物资管理部审核',
                date: ''
            },
            {
                title: '法律事务部审核',
                date: ''
            },
        ]
    })
    $('#projectName').val(data.projectName);
    $('#name').val(data.supplier.name);
    $('#classify').text(data.productType);
    $('#businessLicense').val(data.supplier.businessLicense);
    if(data.supplier.businessExpireDate == '9999-12-31'){
        $('#businessExpireDate').val('长期');
    }else{
        $('#businessExpireDate').val(data.supplier.businessExpireDate);
    }
    // $('#businessExpireDate').val(data.supplier.businessExpireDate);
    $('#businessRegisterMoney').val(data.supplier.businessRegisterMoney);
    $('#productLicence').val(data.supplier.productLicence);
    $('#productExpireDate').val(data.supplier.productExpireDate);
    $('#creditLevel').val((data.supplier.creditLevel != undefined?creditLevelMap[data.supplier.creditLevel]:''));

}

//提交
$('#submit').click(function(){
    $('#bidtd').css({'border':'none'})
    var price = {};
    price.remark = $('#remark').val(),
    price.detail = [];

    var priceList = $('#pricelist').find('tbody').find('tr');//拿到每一行的集合
    $.each(priceList,function(i,data){
        var node = {
            "name": $(data).find('.name').val(),
            "model":$(data).find('.model').val(),
            "price":$(data).find('.price').val(),
            "freight":$(data).find('.freight').val()
        };
        if (node.name && node.model && node.price && node.freight){
            price.detail.push(node);
        }
    })
    console.log(price)

    var obj = {};
    obj.status = 1;
    obj.surveyId = DX.getParam('surveyId');
    obj.price = JSON.stringify(price);
    obj.loadDistance = $('#loadDistance').val();
    obj.honestLevel = $('#honestLevel').val();
    obj.datum = $('input[name=bid]:checked').val();
    obj.datumFile = $('.uploadfile').attr('oid');
    obj.contractNo = $('#contractNo').val();
    obj.companyContract = $('input[name="dan"]:checked').val();
    var flag = true;
    if(DX.isNull(obj.contractNo)){$('.contitle').tip({msg:'不可为空'});flag = false;}
    if(!DX.isNumber(obj.loadDistance)){$('.loadTitle').tip({msg:'请输入数字'});flag = false;}
    if(DX.isNull(obj.price) || price.detail.length == 0){$('.priceTitle').tip({msg:'不可为空'});flag = false;}
    // if(DX.isNull(obj.honestLevel)){$('.hontitle').tip({msg:'不可为空'});flag = false;}
    if(DX.isNull(obj.datum)){$('.bidChoose').tip({msg:'不可为空'});flag = false;}
    if(DX.isNull(obj.datumFile)){$('.uploadfile').tip({msg:'不可为空'});flag = false;}
    if(!flag){return false;}

    for(var i in obj){obj[i] == undefined ? obj[i] = null : obj[i] = obj[i]};
    var that = $(this);
    DX.ajax_method({
        'type':'POST',
        'url':'/materials/supply/contractAudit/addContractAudit',
        'param':obj,
        'change':that[0],
        'callBack':function(res){
            console.log(res)
            if(res.code == 200){
                window.location.href='contract.html';
            }else{
                alert(res.msg);
            }
        }
    })
})


//点击单价弹出可输入表格
$('.pricetableList').hide()
    $('#price').focus(function(){
        $('#price').val('');
        $('.pricetableList').show()
        $('.shade').removeClass('none');
    })
    // 点击添加创建新的一行
    $('body').on('click','.add',function(){
        var html = '';
        html+='<tr id="detail">';
        html+='<td><input type="text" class="sameInput name"></td>';
        html+='<td><input type="text" class="sameInput model"></td>';
        html+='<td><input type="text" class="sameInput price"></td>';
        html+='<td><input type="text" class="sameInput freight"></td>';
        html+='<td style="text-align: center;"><button type="button" class="add upandshow">添加</button><button type="button" class="over upandshow none">删除</button></td>';  
        html+='</tr>';
        $('.add').addClass('none');
        $('.over').removeClass('none');
        $('#pricelist tbody').append(html);
    })
    // 点击删除按键删除整行内容
    $('body').on('click','.over',function(){
        $(this).parent().parent().remove();
    })

    //点击确认  取消  关闭弹窗
    $('#sure').click(function(){
        $('#price').val('点击查看详情');
        $('.pricetableList').hide();
        $('.shade').addClass('none');
    })
    $('#no').click(function(){
        $('#price').val('点击查看详情');
        $('.pricetableList').hide();
        $('.shade').addClass('none');
    })


    
// 获取时间
function getDate(){
    var now = new Date();
    var year = now.getFullYear(); //得到年份
    var month = now.getMonth();//得到月份
    var date = now.getDate();//得到日期
    month = month + 1;
    return year+'/'+month+'/'+date;
}
</script>